package com.genghis.ptas.note;

import com.genghis.core.page.entity.Page;
import com.genghis.core.page.entity.PageParameter;
import com.genghis.ptas.constant.DictConstant;
import com.genghis.ptas.note.entity.Note;
import com.genghis.ptas.note.service.NoteService;
import com.genghis.ptas.note.service.PublicityNoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * User: gaoyang
 * To change this template use File | Settings | File Templates.
 */
@Controller
@Transactional
@RequestMapping("/note/publicity/")
public class PublicityNoteController {

    @Autowired
    private PublicityNoteService publicityNoteService;

    @Autowired
    private NoteService noteService;

    @RequestMapping(value = "listAllPublicityNote", method = {RequestMethod.GET})
    public String listAllUserDo(HttpServletRequest request) {
        request.setAttribute("PAST", DictConstant.PAST);
        request.setAttribute("REJECT", DictConstant.REJECT);
        return "backstage/note/publicity/listAllPublicityNote";
    }

    @RequestMapping(value = "listAllPublicityNote", method = RequestMethod.POST)
    @ResponseBody
    public Page listAllPermission(PageParameter pageParameter, Note note) {
        return publicityNoteService.findPublicityNotePageList(pageParameter, note);
    }

    @RequestMapping(value = "auditNote", method = {RequestMethod.GET})
    public String auditNote(HttpServletRequest request, @RequestParam("id") int id, @RequestParam("noteId") int noteId) {
        Note note = noteService.findNoteById(noteId);
        request.setAttribute("note", note);
        request.setAttribute("id", id);
        request.setAttribute("PAST", DictConstant.PAST);
        request.setAttribute("REJECT", DictConstant.REJECT);
        return "backstage/note/publicity/auditNote";
    }

    @RequestMapping(value = "auditNote", method = RequestMethod.DELETE)
    @ResponseBody
    public void pastNote(@RequestParam("ids") String ids, @RequestParam("state") int state) {
        publicityNoteService.auditNotes(ids, state);
    }
}
